package ctxdata

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"strconv"
)

// CtxKeyJwtUserId get uid from ctx
var CtxKeyJwtUserId = "jwtUserId"

func GetUidFromCtx(ctx context.Context) int64 {
	var uid int64
	if jsonUid, ok := ctx.Value(CtxKeyJwtUserId).(string); ok {
		if int64Uid, err := strconv.ParseInt(jsonUid, 10, 64); err == nil {
			uid = int64Uid
		} else {
			logx.WithContext(ctx).Errorf("GetUidFromCtx err : %+v", err)
		}
	} else {
		logx.Errorf("GetUidFromCtx,err:%s", ctx.Value(CtxKeyJwtUserId))
	}
	return uid
}
